package com.akrc.blog.controller;

import com.akrc.blog.mapper.PostMapper;
import com.akrc.blog.model.Post;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PostController {
	final PostMapper postMapper;

	PostController(PostMapper postMapper) {
		this.postMapper = postMapper;
	}

	@GetMapping("/post/{id}")
	Post post(@PathVariable Integer id) {
		postMapper.updateCount(id);
		return postMapper.getPost(id);
	}

	@GetMapping("/postlist/{pid}")
	List<Post> PostList(@PathVariable String pid) {
		return postMapper.PostList(Integer.valueOf(pid));
	}
}
